import request from '../utils/request'

//...... 各个axios后台调用

//登录接口
export const getLogin = (info)=>{
    return request.post("user/login", info)
}
//注册
export const register = (info)=>{
    return request.post("user/register", info)
}


//通过token获取用户的信息
export const getUserInfo = (info)=>{
    return request.get("user/getUserInfo")
}


//案例
export const getShowNewsDetail = (hid)=>{
    return request({
        method: 'post',
        url: 'portal/showHeadlineDetail',
        data: `hid=${hid}`
    })
}


//delete 例子
export const deleteNewsByHid = (hid)=>{
    return request({
        method: 'delete',
        url: 'headline/removeByHid',
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `hid=${hid}`
    })
}

//添加宠物
export const addPet = (info)=>{

    return request.post("pet/addPet",info)

}
//获取寻宠启示信息
export const getSeekInfo = ()=>{
    return request.get('seek/getSeeking')
}
// export const getSeekById = (id)=>{
//     return request.get('seek/getSeekById',id)
// }
export const getSeekById = (id)=>{
    return request({
        method:'post',
        url:'seek/getSeekById',
        data:`id=${id}`
    })
}
//获取评论表
export const getSeekCommentById = (id)=>{
    return request({
        method:'post',
        url:'seek/getSeekCommentById',
        data:`id=${id}`
    })
}
export const getSeekName = (id)=>{
    return request({
        method: 'post',
        url: "user/getSeekName",
        data: `id=${id}`
    })
}
// export const publishSeeking = (formData)=>{
//     return request({
//         method: 'post',
//         url: "seek/publish",
//         headers: {
//             'Content-Type': 'multipart/form-data'
//         },
//         data: `formData=${formData}`
//     })
// }

export const publishSeeking =  (formData)=>{
    return request.post('seek/publish', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
}
export const publishComment =  (data)=>{
    return request.post('seek/publishComment', data)
}


export const selectProdetailById =(productId)=>{
     return request({
        method: 'post',
        url: 'product/queryProDetailById',
        data: `productId=${productId}`
    })

}

//查询所有商品
export const queryALLProducts =()=>{
    return request.get("product/listAllProducts")
}

//创建订单
export const getOrder =(info)=>{
    return request.post("order/createOrder",info)
}

//查询所有地址
export const queryALLAddress =()=>{
    return request.post("userAddress/selectAllAddress")
}

//新增地址
export const insertAddress =(info)=>{
    return request.post("userAddress/insertAddress",info)
}

//删除地址
export const deleteAddress = (id)=>{
    return request({
        method: 'delete',
        url: 'userAddress/deleteAddressById',
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `id=${id}`
    })
}

//修改订单
export const updateAddress =(info)=>{
    return request.post("userAddress/updateAddress",info)
}

//根据用户id查地址
export const queryAddresstByUid =(userId)=>{
     return request({
        method: 'post',
        url: 'userAddress/selectByUid',
        data: `userId=${userId}`
    })
}

//根据地址id查地址
export const queryAddresstByid =(id)=>{
     return request({
        method: 'post',
        url: 'userAddress/selectByid',
        data: `id=${id}`
    })
}

//设置默认地址
export const setDefaultAddress =(id)=>{
     return request({
        method: 'post',
        url: 'userAddress/setDefaultAddressById',
        data: `id=${id}`
    })
}


//获取帖子列表
export const getFindAllTopics = ()=>{
    return request.get("topic/findAllTopic")
}

//根据帖子id获取内容信息
export const showTopicDetail = (topicId)=>{
    return request({
        method: 'post',
        url: 'topic/showTopicDetail',
        data: `topicId=${topicId}`
    })
}

// export const showTopicDetail = (topicId) => {
//     return request({
//         method: 'get',  // 改为GET请求
//         url: `topic/showTopicDetail?topicId=${topicId}`
//     })
// }
